import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import {useRouter} from 'vue-router'


export const useMenuStore = defineStore('menu', () => {
    let router = useRouter();
    let tabs = ref([]);
    function addTab(menu){
        if(tabs.value.findIndex(item=>item.id==menu.id)==-1){
            tabs.value.push(menu);
        }
    }
    function dropTab(id){
        tabs.value = tabs.value.filter(item=>item.id!=id);
        router.push(tabs.value[tabs.value.length-1].path);
    }
    return {tabs,addTab,dropTab}
})